# coding=utf-8

import re
import requests
import time

respose=requests.get('http://www.xiaohuar.com/v/')

urls=re.findall(r'class="items".*?href="(.*?)"',respose.text,re.S)  #re.S 把文本信息转换成1行匹配

for index in range (len(urls)):
    try:
        url=urls[index]
        result=requests.get(url)
        mp4_url=re.findall(r'id="media".*?src="(.*?)"',result.text,re.S)[0]

        video=requests.get(mp4_url)
        
        with open("downloads/" + str(index) + '.mp4','wb') as f:
            f.write(video.content)
        print(r"%s：处理成功"%mp4_url)
    except BaseException:
        print(r"%s：失败成功"%mp4_url)